package com.example.hasee.weather;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hasee.data.entity.Weather;
import com.example.hasee.libraryreservation.R;

import java.util.WeakHashMap;

public class WeatherFragment extends Fragment implements WeatherContract.View{
    private ImageView img;
    private TextView tv;
    private WeakHashMap<String,Integer> icons;
    private WeatherContract.Presenter mPresenter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_weather, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        img=view.findViewById(R.id.img);
        tv=view.findViewById(R.id.tv);
        mPresenter=new WeatherPresenter(this);
        icons=new WeakHashMap<>();
        icons.put("14",R.drawable.p0);
        mPresenter.getWeatherInfo();
    }

    @Override
    public void weatherInfo(Weather weather) {
        img.setImageResource(icons.get(weather.getFa()));
        tv.setText(weather.getTemperature());
    }
}
